package visao.aluno;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.JScrollPane;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.border.EmptyBorder;

import modelagem.Aluno;

import com.towel.el.annotation.AnnotationResolver;
import com.towel.swing.table.ObjectTableModel;

import controle.aluno.AcoesBuscaAluno;

@SuppressWarnings("serial")
public class BuscadeAlunos extends JDialog{

	private final JPanel contentPanel = new JPanel();
	private JTable table;
	private JTextField textNome, textMat;
	private ObjectTableModel<Aluno> modeloTabela;
	private AnnotationResolver aR;
	private interfaceAluno ia;
	private AcoesBuscaAluno AcoesBuscaAluno;

	
	public BuscadeAlunos(interfaceAluno ia) {
		this.ia = ia;
		AcoesBuscaAluno = new AcoesBuscaAluno(this);
		setBounds(100, 100, 450, 300);
		this.setSize(505, 400);
		this.setLocationRelativeTo(null);
		this.setResizable(false);
		this.setModal(true);
		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		
		aR = new AnnotationResolver(Aluno.class);
		modeloTabela = new ObjectTableModel<Aluno>(aR, "matricula,nome");
		
		JLabel lblBuscarNome = new JLabel("Buscar Nome:");
		lblBuscarNome.setBounds(10, 11, 106, 14);
		contentPanel.add(lblBuscarNome);
		
		textNome = new JTextField();
		textNome.setBounds(97, 8, 380, 20);
		contentPanel.add(textNome);
		textNome.setColumns(10);
		
		JLabel lblBuscarMatricula = new JLabel("Buscar Matricula:");
		lblBuscarMatricula.setBounds(10, 36, 106, 14);
		contentPanel.add(lblBuscarMatricula);
		
		table = new JTable(modeloTabela);
		
		table.getColumnModel().getColumn(0).setPreferredWidth(10);
		table.getColumnModel().getColumn(1).setPreferredWidth(300);
		
		JScrollPane sP = new JScrollPane(table);
		sP.setBounds(10, 56, 467, 275);
		contentPanel.add(sP, JTable.CENTER_ALIGNMENT);
		
		textMat = new JTextField();
		textMat.setColumns(10);
		textMat.setBounds(107, 33, 96, 20);
		contentPanel.add(textMat);
		{
			JPanel buttonPane = new JPanel();
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			buttonPane.setLayout(new FlowLayout(FlowLayout.CENTER, 50, 5));
			
			JButton btnSelecionar = new JButton("Selecionar");
			btnSelecionar.addActionListener(AcoesBuscaAluno);
			btnSelecionar.setName("Selecionar");
			buttonPane.add(btnSelecionar);
			
			JButton btnBuscar = new JButton("Buscar");
			btnBuscar.setName("Buscar");
			btnBuscar.addActionListener(AcoesBuscaAluno);
			buttonPane.add(btnBuscar);
			
			JButton btnCancelar = new JButton("Fechar");
			btnCancelar.setName("Cancelar");
			btnCancelar.addActionListener(AcoesBuscaAluno);
			buttonPane.add(btnCancelar);
		}
	}


	public JTable getTable() {
		return table;
	}


	public void setTable(JTable table) {
		this.table = table;
	}


	public JTextField getTextField() {
		return textNome;
	}


	public void setTextField(JTextField textField) {
		this.textNome = textField;
	}


	public JTextField getTextField_1() {
		return textMat;
	}


	public void setTextField_1(JTextField textField_1) {
		this.textMat = textField_1;
	}


	public ObjectTableModel<Aluno> getModeloTabela() {
		return modeloTabela;
	}


	public void setModeloTabela(ObjectTableModel<Aluno> modeloTabela) {
		this.modeloTabela = modeloTabela;
	}


	public AnnotationResolver getaR() {
		return aR;
	}


	public void setaR(AnnotationResolver aR) {
		this.aR = aR;
	}


	public interfaceAluno getIa() {
		return ia;
	}


	public void setIa(interfaceAluno ia) {
		this.ia = ia;
	}


	public AcoesBuscaAluno getAcoesBuscaAluno() {
		return AcoesBuscaAluno;
	}


	public void setAcoesBuscaAluno(AcoesBuscaAluno acoesBuscaAluno) {
		AcoesBuscaAluno = acoesBuscaAluno;
	}


	public JPanel getContentPanel() {
		return contentPanel;
	}
}
